//
//  ConvenientlyTakeVC.m
//  ConvenientlyTake
//
//  Created by 张奇 on 2022/12/20.
//

#import "ConvenientlyTakeVC.h"
#import "JXCategoryTitleView.h"
#import "JXCategoryIndicatorLineView.h"
#import "ConvenientlyTakeListView.h"
#import "ConvenientlyTakeAddVC.h"

@interface ConvenientlyTakeVC ()<UIScrollViewDelegate, JXCategoryViewDelegate>
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) NSArray <NSString *> *titles;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic , strong) NSMutableArray *tableViewArray;

@end

@implementation ConvenientlyTakeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self setupUI];
}

- (void)initData {
    self.index = 0;
}

- (void)setupNavigationItems {
    [super setupNavigationItems];
    [self setNavStyleWhite];
    [self setRightBarButtonImage:@"convenientlyTake_add" selector:@selector(clickAddAction:)];
}

- (void)clickAddAction:(UIBarButtonItem *)sender {
    ConvenientlyTakeAddVC *addVC = [[ConvenientlyTakeAddVC alloc] init];
    [self pushViewController:addVC complent:nil];
}

- (void)setupUI{
   
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 55)];
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.titleFont = TGAutoFont(15);
//    self.categoryView.titleSelectedFont = TGSemiboldFont(16);
    self.categoryView.titleSelectedColor = GlobalBarTinColor;
    self.categoryView.titleColor = RGBA(136, 136, 136, 1);
    self.categoryView.titles = self.titles;
    
    /**线条*/
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorWidth = RatioWidth(26);
    lineView.indicatorHeight = RatioWidth(2);
    lineView.indicatorColor = GlobalBarTinColor;
    self.categoryView.indicators = @[lineView];
    self.categoryView.contentScrollView = self.scrollView;
    self.categoryView.delegate = self;
    [self.view addSubview:self.categoryView];
    
    // 创建table 视图
    for (int i = 0; i < self.titles.count; i++) {
        ConvenientlyTakeListView *tableView = [[ConvenientlyTakeListView alloc] initWithFrame:CGRectMake(i * SCREEN_WIDTH, 0, SCREEN_WIDTH, self.scrollView.frame.size.height)];
        tableView.randomClapState = i+1;
        [self.tableViewArray addObject:tableView];
        [self.scrollView addSubview:tableView];
    }
}

- (NSArray<NSString *> *)titles {
    if (!_titles) {
        _titles = @[@"待受理", @"处置中", @"已办结", @"不予受理"];
    }
    return _titles;
}

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        CGFloat scrollH = SCREEN_HEIGHT - NavBarHeight - 55 - TGTabBarHeight;
        UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 55, SCREEN_WIDTH, scrollH)];
        sv.backgroundColor = UIColorForBackground;
        sv.bounces = NO;
        sv.delegate = self;
        sv.pagingEnabled = YES;
        sv.showsHorizontalScrollIndicator = NO;
        sv.showsVerticalScrollIndicator = NO;
        sv.alwaysBounceHorizontal = YES;
        sv.bouncesZoom = NO;
        sv.contentSize = CGSizeMake(SCREEN_WIDTH * self.titles.count, 0);
        [self.view addSubview:sv];
        _scrollView = sv;
    }
    return _scrollView;
}
- (NSMutableArray *)tableViewArray{
    if(!_tableViewArray){
        _tableViewArray = [NSMutableArray array];
    }
    return _tableViewArray;
}

@end
